package com.ymatou.query.seller.trading.api.parameter.Seller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.ymatou.query.seller.trading.api.parameter.FundSummary;
import com.ymatou.query.seller.trading.api.parameter.Sp_GetOrdersByOrderIds_v2;
import com.ymatou.query.seller.trading.api.parameter.info.OrderBasicInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderConsigneeInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderConsumerInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderPaymentDetail;
import com.ymatou.query.seller.trading.api.parameter.info.OrderPaymentInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderProductInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderProductRefundInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderSellerInfo;
import com.ymatou.query.seller.trading.api.parameter.info.OrderTransferInfo;
import com.ymatou.query.seller.trading.api.parameter.info.SellerOrderInfo;
import com.ymttest.utils.DataUtil;

public class Common {
	public static List<SellerOrderInfo> GetSellerOrders(int seller,
			List<Integer> orders) {
		Sp_GetOrdersByOrderIds_v2 sp = new Sp_GetOrdersByOrderIds_v2();
		sp.setSeller(seller);
		sp.setOrders(orders);
		sp.execute();
		List<SellerOrderInfo> result = new ArrayList<SellerOrderInfo>();
		if (seller > 0 && DataUtil.isNullOrEmpty(orders) == false) {
			result = ConvertToSellerOrders(sp);
		}
		return result;
	}

	static class DbEntities {
		public static class OrderFundSummary extends FundSummary {
			private int OrderId;

			public int getOrderId() {
				return OrderId;
			}

			public void setOrderId(int orderId) {
				OrderId = orderId;
			}

			public static void main(String[] args) {
				DataUtil.abc(DbEntities.OrderFundSummary.class, "o", "m");
			}

		}

		private static class OrderInfo {
			private int Basic_ID;
			private String Basic_CreatedTime;
			private String Basic_CancelledTime;
			private String Basic_AcceptedTime;
			private String Basic_Source;
			private int Basic_Type;
			private int Basic_Status;
			private int Basic_RiskStatus;
			private BigDecimal Basic_TotalPrice;
			private BigDecimal Basic_Discount;
			private String Buyer_ID;
			private String Buyer_LoginId;
			private String Buyer_Email;
			private String Buyer_NickName;
			private String Buyer_Message;
			private String Seller_ID;
			private String Seller_LoginId;
			private String Seller_Email;
			private String Seller_Comment;
			private String Consignee_Name;
			private String Consignee_Address;
			private String Consignee_Postcode;
			private String Consignee_Phone;
			private String Consignee_Tel;
			private BigDecimal Payment_ActualPaid;
			private String Payment_1_PaidTime;
			private String Payment_1_InternalTradingNo;
			private String Payment_1_ExternalTradingNo;
			private String Payment_2_PaidTime;
			private String Transfer_DeliveredTime;
			private String Transfer_ReceiptConfirmedTime;

			public static void main(String[] args) {
				DataUtil.abc(DbEntities.OrderInfo.class, "o", "m");
			}

			public int getBasic_ID() {
				return Basic_ID;
			}

			public void setBasic_ID(int basic_ID) {
				Basic_ID = basic_ID;
			}

			public String getBasic_CreatedTime() {
				return Basic_CreatedTime;
			}

			public void setBasic_CreatedTime(String basic_CreatedTime) {
				Basic_CreatedTime = basic_CreatedTime;
			}

			public String getBasic_CancelledTime() {
				return Basic_CancelledTime;
			}

			public void setBasic_CancelledTime(String basic_CancelledTime) {
				Basic_CancelledTime = basic_CancelledTime;
			}

			public String getBasic_AcceptedTime() {
				return Basic_AcceptedTime;
			}

			public void setBasic_AcceptedTime(String basic_AcceptedTime) {
				Basic_AcceptedTime = basic_AcceptedTime;
			}

			public String getBasic_Source() {
				return Basic_Source;
			}

			public void setBasic_Source(String basic_Source) {
				Basic_Source = basic_Source;
			}

			public int getBasic_Type() {
				return Basic_Type;
			}

			public void setBasic_Type(int basic_Type) {
				Basic_Type = basic_Type;
			}

			public int getBasic_Status() {
				return Basic_Status;
			}

			public void setBasic_Status(int basic_Status) {
				Basic_Status = basic_Status;
			}

			public int getBasic_RiskStatus() {
				return Basic_RiskStatus;
			}

			public void setBasic_RiskStatus(int basic_RiskStatus) {
				Basic_RiskStatus = basic_RiskStatus;
			}

			public BigDecimal getBasic_TotalPrice() {
				return Basic_TotalPrice;
			}

			public void setBasic_TotalPrice(BigDecimal basic_TotalPrice) {
				Basic_TotalPrice = basic_TotalPrice;
			}

			public BigDecimal getBasic_Discount() {
				return Basic_Discount;
			}

			public void setBasic_Discount(BigDecimal basic_Discount) {
				Basic_Discount = basic_Discount;
			}

			public String getBuyer_ID() {
				return Buyer_ID;
			}

			public void setBuyer_ID(String buyer_ID) {
				Buyer_ID = buyer_ID;
			}

			public String getBuyer_LoginId() {
				return Buyer_LoginId;
			}

			public void setBuyer_LoginId(String buyer_LoginId) {
				Buyer_LoginId = buyer_LoginId;
			}

			public String getBuyer_Email() {
				return Buyer_Email;
			}

			public void setBuyer_Email(String buyer_Email) {
				Buyer_Email = buyer_Email;
			}

			public String getBuyer_NickName() {
				return Buyer_NickName;
			}

			public void setBuyer_NickName(String buyer_NickName) {
				Buyer_NickName = buyer_NickName;
			}

			public String getBuyer_Message() {
				return Buyer_Message;
			}

			public void setBuyer_Message(String buyer_Message) {
				Buyer_Message = buyer_Message;
			}

			public String getSeller_ID() {
				return Seller_ID;
			}

			public void setSeller_ID(String seller_ID) {
				Seller_ID = seller_ID;
			}

			public String getSeller_LoginId() {
				return Seller_LoginId;
			}

			public void setSeller_LoginId(String seller_LoginId) {
				Seller_LoginId = seller_LoginId;
			}

			public String getSeller_Email() {
				return Seller_Email;
			}

			public void setSeller_Email(String seller_Email) {
				Seller_Email = seller_Email;
			}

			public String getSeller_Comment() {
				return Seller_Comment;
			}

			public void setSeller_Comment(String seller_Comment) {
				Seller_Comment = seller_Comment;
			}

			public String getConsignee_Name() {
				return Consignee_Name;
			}

			public void setConsignee_Name(String consignee_Name) {
				Consignee_Name = consignee_Name;
			}

			public String getConsignee_Address() {
				return Consignee_Address;
			}

			public void setConsignee_Address(String consignee_Address) {
				Consignee_Address = consignee_Address;
			}

			public String getConsignee_Postcode() {
				return Consignee_Postcode;
			}

			public void setConsignee_Postcode(String consignee_Postcode) {
				Consignee_Postcode = consignee_Postcode;
			}

			public String getConsignee_Phone() {
				return Consignee_Phone;
			}

			public void setConsignee_Phone(String consignee_Phone) {
				Consignee_Phone = consignee_Phone;
			}

			public String getConsignee_Tel() {
				return Consignee_Tel;
			}

			public void setConsignee_Tel(String consignee_Tel) {
				Consignee_Tel = consignee_Tel;
			}

			public BigDecimal getPayment_ActualPaid() {
				return Payment_ActualPaid;
			}

			public void setPayment_ActualPaid(BigDecimal payment_ActualPaid) {
				Payment_ActualPaid = payment_ActualPaid;
			}

			public String getPayment_1_PaidTime() {
				return Payment_1_PaidTime;
			}

			public void setPayment_1_PaidTime(String payment_1_PaidTime) {
				Payment_1_PaidTime = payment_1_PaidTime;
			}

			public String getPayment_1_InternalTradingNo() {
				return Payment_1_InternalTradingNo;
			}

			public void setPayment_1_InternalTradingNo(
					String payment_1_InternalTradingNo) {
				Payment_1_InternalTradingNo = payment_1_InternalTradingNo;
			}

			public String getPayment_1_ExternalTradingNo() {
				return Payment_1_ExternalTradingNo;
			}

			public void setPayment_1_ExternalTradingNo(
					String payment_1_ExternalTradingNo) {
				Payment_1_ExternalTradingNo = payment_1_ExternalTradingNo;
			}

			public String getPayment_2_PaidTime() {
				return Payment_2_PaidTime;
			}

			public void setPayment_2_PaidTime(String payment_2_PaidTime) {
				Payment_2_PaidTime = payment_2_PaidTime;
			}

			public String getTransfer_DeliveredTime() {
				return Transfer_DeliveredTime;
			}

			public void setTransfer_DeliveredTime(String transfer_DeliveredTime) {
				Transfer_DeliveredTime = transfer_DeliveredTime;
			}

			public String getTransfer_ReceiptConfirmedTime() {
				return Transfer_ReceiptConfirmedTime;
			}

			public void setTransfer_ReceiptConfirmedTime(
					String transfer_ReceiptConfirmedTime) {
				Transfer_ReceiptConfirmedTime = transfer_ReceiptConfirmedTime;
			}
		}

		private static class ProductInfo {
			private int OrderId;

			// / <summary>
			// / 商品分摊的商家优惠金额
			// / </summary>
			private BigDecimal PartialSellerCoupon = new BigDecimal(0);

			// 商品分摊的折扣调整金额
			private BigDecimal PartialDiscount = new BigDecimal(0);

			// 商品分摊的商家满减优惠金额
			private BigDecimal PartialSellerPromotion = new BigDecimal(0);

			public BigDecimal getPartialSellerCoupon() {
				return PartialSellerCoupon;
			}

			public void setPartialSellerCoupon(BigDecimal partialSellerCoupon) {
				PartialSellerCoupon = partialSellerCoupon;
			}

			public BigDecimal getPartialDiscount() {
				return PartialDiscount;
			}

			public void setPartialDiscount(BigDecimal partialDiscount) {
				PartialDiscount = partialDiscount;
			}

			public BigDecimal getPartialSellerPromotion() {
				return PartialSellerPromotion;
			}

			public void setPartialSellerPromotion(
					BigDecimal partialSellerPromotion) {
				PartialSellerPromotion = partialSellerPromotion;
			}

			// / <summary>
			// / 规格ID
			// / </summary>
			private String CatalogId;

			// / <summary>
			// / 商品ID
			// / </summary>
			private String ProductId;

			// / <summary>
			// / 商品类型
			// / </summary>
			private int CatalogType;

			// / <summary>
			// / 套餐编号
			// / </summary>
			private String PackageNo;

			// / <summary>
			// / 活动ID
			// / </summary>
			private int ActivityId;

			// / <summary>
			// / 商品名称
			// / </summary>
			private String Name;

			// / <summary>
			// / 商品分类一级
			// / </summary>
			private int Category1;

			// / <summary>
			// / 商品分类二级
			// / </summary>
			private int Category2;

			// / <summary>
			// / 商品分类三级
			// / </summary>
			private int Category3;

			// / <summary>
			// / SKU
			// / </summary>
			private String SKU;

			// / <summary>
			// / 单价
			// / </summary>
			private BigDecimal Price;

			// / <summary>
			// / 数量
			// / </summary>
			private int Count;

			// / <summary>
			// / 总价=单价*数量
			// / </summary>
			private BigDecimal TotalPrice;

			// / <summary>
			// / 商品规格
			// / </summary>
			private String PropertyInfo;

			// / <summary>
			// / 保税区
			// / </summary>
			private int BondedArea;

			// / <summary>
			// / 配送方式
			// / </summary>
			private int Logistics;

			private BigDecimal OriginalPrice;
			private BigDecimal PartialFreight;
			private BigDecimal PartialYmtCoupon;

			// / <summary>
			// / 退货退款状态
			// / </summary>
			private Integer SalesRefundStatus;

			// / <summary>
			// / 退款状态
			// / </summary>
			private Integer RefundStatus;

			// / <summary>
			// / 退款金额
			// / </summary>
			private BigDecimal RefundAmount;

			// / <summary>
			// / 退现金金额
			// / </summary>
			private BigDecimal RefundedAmountOfCash;

			// / <summary>
			// / 退红包金额
			// / </summary>
			private BigDecimal RefundedAmountOfGift;

			// / <summary>
			// / 平台优惠券
			// / </summary>
			private BigDecimal SettlementAmountOfCoupon;

			// / <summary>
			// / 退货退款商品数量
			// / </summary>
			private BigDecimal RefundProductNum;

			// / <summary>
			// / 品牌ID
			// / </summary>
			private int BrandId;

			public int getOrderId() {
				return OrderId;
			}

			public static void main(String[] args) {
				DataUtil.abc(DbEntities.ProductInfo.class, "o", "m");
			}

			public void setOrderId(int orderId) {
				OrderId = orderId;
			}

			public String getCatalogId() {
				return CatalogId;
			}

			public void setCatalogId(String catalogId) {
				CatalogId = catalogId;
			}

			public String getProductId() {
				return ProductId;
			}

			public void setProductId(String productId) {
				ProductId = productId;
			}

			public int getCatalogType() {
				return CatalogType;
			}

			public void setCatalogType(int catalogType) {
				CatalogType = catalogType;
			}

			public String getPackageNo() {
				return PackageNo;
			}

			public void setPackageNo(String packageNo) {
				PackageNo = packageNo;
			}

			public int getActivityId() {
				return ActivityId;
			}

			public void setActivityId(int activityId) {
				ActivityId = activityId;
			}

			public String getName() {
				return Name;
			}

			public void setName(String name) {
				Name = name;
			}

			public int getCategory1() {
				return Category1;
			}

			public void setCategory1(int category1) {
				Category1 = category1;
			}

			public int getCategory2() {
				return Category2;
			}

			public void setCategory2(int category2) {
				Category2 = category2;
			}

			public int getCategory3() {
				return Category3;
			}

			public void setCategory3(int category3) {
				Category3 = category3;
			}

			public String getSKU() {
				return SKU;
			}

			public void setSKU(String sKU) {
				SKU = sKU;
			}

			public BigDecimal getPrice() {
				return Price;
			}

			public void setPrice(BigDecimal price) {
				Price = price;
			}

			public int getCount() {
				return Count;
			}

			public void setCount(int count) {
				Count = count;
			}

			public BigDecimal getTotalPrice() {
				return TotalPrice;
			}

			public void setTotalPrice(BigDecimal totalPrice) {
				TotalPrice = totalPrice;
			}

			public String getPropertyInfo() {
				return PropertyInfo;
			}

			public void setPropertyInfo(String propertyInfo) {
				PropertyInfo = propertyInfo;
			}

			public int getBondedArea() {
				return BondedArea;
			}

			public void setBondedArea(int bondedArea) {
				BondedArea = bondedArea;
			}

			public int getLogistics() {
				return Logistics;
			}

			public void setLogistics(int logistics) {
				Logistics = logistics;
			}

			public BigDecimal getOriginalPrice() {
				return OriginalPrice;
			}

			public void setOriginalPrice(BigDecimal originalPrice) {
				OriginalPrice = originalPrice;
			}

			public BigDecimal getPartialFreight() {
				return PartialFreight;
			}

			public void setPartialFreight(BigDecimal partialFreight) {
				PartialFreight = partialFreight;
			}

			public BigDecimal getPartialYmtCoupon() {
				return PartialYmtCoupon;
			}

			public void setPartialYmtCoupon(BigDecimal partialYmtCoupon) {
				PartialYmtCoupon = partialYmtCoupon;
			}

			public Integer getSalesRefundStatus() {
				return SalesRefundStatus;
			}

			public void setSalesRefundStatus(Integer salesRefundStatus) {
				SalesRefundStatus = salesRefundStatus;
			}

			public Integer getRefundStatus() {
				return RefundStatus;
			}

			public void setRefundStatus(Integer refundStatus) {
				RefundStatus = refundStatus;
			}

			public BigDecimal getRefundAmount() {
				return RefundAmount;
			}

			public void setRefundAmount(BigDecimal refundAmount) {
				RefundAmount = refundAmount;
			}

			public BigDecimal getRefundedAmountOfCash() {
				return RefundedAmountOfCash;
			}

			public void setRefundedAmountOfCash(BigDecimal refundedAmountOfCash) {
				RefundedAmountOfCash = refundedAmountOfCash;
			}

			public BigDecimal getRefundedAmountOfGift() {
				return RefundedAmountOfGift;
			}

			public void setRefundedAmountOfGift(BigDecimal refundedAmountOfGift) {
				RefundedAmountOfGift = refundedAmountOfGift;
			}

			public BigDecimal getSettlementAmountOfCoupon() {
				return SettlementAmountOfCoupon;
			}

			public void setSettlementAmountOfCoupon(
					BigDecimal settlementAmountOfCoupon) {
				SettlementAmountOfCoupon = settlementAmountOfCoupon;
			}

			public BigDecimal getRefundProductNum() {
				return RefundProductNum;
			}

			public void setRefundProductNum(BigDecimal refundProductNum) {
				RefundProductNum = refundProductNum;
			}

			public int getBrandId() {
				return BrandId;
			}

			public void setBrandId(int brandId) {
				BrandId = brandId;
			}

		}
	}

	public static List<SellerOrderInfo> ConvertToSellerOrders(
			Sp_GetOrdersByOrderIds_v2 sp) {
		if (sp == null) {
			return null;
		}
		List<DbEntities.OrderInfo> orders = convertToOrders(sp);
		List<DbEntities.ProductInfo> products = convertToProducts(sp);
		List<DbEntities.OrderFundSummary> fundSummaries = convertToFundSummaries(sp);

		List<SellerOrderInfo> result = new ArrayList<SellerOrderInfo>();
		if (DataUtil.isNullOrEmpty(orders) == false) {
			for (DbEntities.OrderInfo o : orders) {
				SellerOrderInfo soi = new SellerOrderInfo();
				soi.setBasic(GetBasicInfo(o));
				soi.setBuyer(GetBuerInfo(o));
				soi.setSeller(GetSellerInfo(o));
				soi.setConsignee(GetConsigneeInfo(o));
				DbEntities.OrderFundSummary summary = null;
				List<DbEntities.OrderFundSummary> t1 = fundSummaries.stream()
						.filter(x -> x.getOrderId() == o.getBasic_ID())
						.collect(Collectors.toList());
				if (t1.size() > 0) {
					summary = t1.get(0);
				}
				soi.setPayment(GetPaymentInfo(o, summary));
				soi.setTransfer(GetTransferInfo(o));
				soi.setProducts(GetProductInfos(products.stream()
						.filter(x -> x.getOrderId() == o.getBasic_ID())
						.collect(Collectors.toList())));
				result.add(Init(soi));
			}
		}

		return result;
	}

	private static List<DbEntities.OrderFundSummary> convertToFundSummaries(
			Sp_GetOrdersByOrderIds_v2 sp) {
		List<DbEntities.OrderFundSummary> l = new ArrayList<DbEntities.OrderFundSummary>();
		if (!DataUtil.isNullOrEmpty(sp.getOrderStateList())) {
			for (Map m : sp.getOrderStateList()) {
				DbEntities.OrderFundSummary o = new DbEntities.OrderFundSummary();
				o.setOrderId(DataUtil.Integerr.GetValueOrDefault(m
						.get("OrderId")));
				o.setFirstPayProductPrice(DataUtil.BigDecimall
						.GetValueOrDefault(m.get("FirstPayProductPrice")));
				o.setFreight(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("Freight")));
				o.setOrderDiscount(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("OrderDiscount")));
				o.setPaidCash(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("PaidCash")));
				o.setPaidFreeCard(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("PaidFreeCard")));
				o.setPaidGift(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("PaidGift")));
				o.setPaidSellerCoupon(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("PaidSellerCoupon")));
				o.setPaidYmtCoupon(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("PaidYmtCoupon")));
				o.setPostPaidCash(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("PostPaidCash")));
				o.setPostPaidGift(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("PostPaidGift")));
				o.setPostPayDiscount(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("PostPayDiscount")));
				o.setTotalActivityPrice(DataUtil.BigDecimall
						.GetValueOrDefault(m.get("TotalActivityPrice")));
				o.setTotalCanceledCash(DataUtil.BigDecimall.GetValueOrNull(m
						.get("TotalCanceledCash")));
				o.setTotalCanceledYmtCoupon(DataUtil.BigDecimall
						.GetValueOrNull(m.get("TotalCanceledYmtCoupon")));
				o.setTotalProductPrice(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("TotalProductPrice")));
				o.setTotalRefundedCash(DataUtil.BigDecimall.GetValueOrNull(m
						.get("TotalRefundedCash")));
				o.setTotalRefundedGift(DataUtil.BigDecimall.GetValueOrNull(m
						.get("TotalRefundedGift")));
				o.setTotalRefundedYmtCoupon(DataUtil.BigDecimall
						.GetValueOrNull(m.get("TotalRefundedYmtCoupon")));
				l.add(o);
			}
		}
		return l;
	}

	private static List<DbEntities.ProductInfo> convertToProducts(
			Sp_GetOrdersByOrderIds_v2 sp) {
		List<DbEntities.ProductInfo> l = new ArrayList<DbEntities.ProductInfo>();
		if (!DataUtil.isNullOrEmpty(sp.getOrderInfoList())) {
			for (Map m : sp.getOrderInfoList()) {

				DbEntities.ProductInfo o = new DbEntities.ProductInfo();

				o.setOrderId(DataUtil.Integerr.GetValueOrDefault(m
						.get("OrderId")));
				o.setCatalogId(DataUtil.Stringg.getValueOrNull(m
						.get("CatalogId")));
				o.setProductId(DataUtil.Stringg.getValueOrNull(m
						.get("ProductId")));
				o.setCatalogType(DataUtil.Integerr.GetValueOrDefault(m
						.get("CatalogType")));
				o.setPackageNo(DataUtil.Stringg.getValueOrNull(m
						.get("PackageNo")));
				o.setActivityId(DataUtil.Integerr.GetValueOrDefault(m
						.get("ActivityId")));
				o.setName(DataUtil.Stringg.getValueOrNull(m.get("Name")));
				o.setCategory1(DataUtil.Integerr.GetValueOrDefault(m
						.get("Category1")));
				o.setCategory2(DataUtil.Integerr.GetValueOrDefault(m
						.get("Category2")));
				o.setCategory3(DataUtil.Integerr.GetValueOrDefault(m
						.get("Category3")));
				o.setSKU(DataUtil.Stringg.getValueOrNull(m.get("SKU")));
				o.setPrice(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("Price")));
				o.setCount(DataUtil.Integerr.GetValueOrDefault(m.get("Count")));
				o.setTotalPrice(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("TotalPrice")));
				o.setPropertyInfo(DataUtil.Stringg.getValueOrNull(m
						.get("PropertyInfo")));
				o.setBondedArea(DataUtil.Integerr.GetValueOrDefault(m
						.get("BondedArea")));
				o.setLogistics(DataUtil.Integerr.GetValueOrDefault(m
						.get("Logistics")));
				o.setOriginalPrice(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("OriginalPrice")));
				o.setPartialFreight(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("PartialFreight")));
				o.setPartialYmtCoupon(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("PartialYmtCoupon")));
				o.setSalesRefundStatus(DataUtil.Integerr.GetValueOrNull(m
						.get("SalesRefundStatus")));
				o.setRefundStatus(DataUtil.Integerr.GetValueOrNull(m
						.get("RefundStatus")));
				o.setRefundAmount(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("RefundAmount")));
				o.setRefundedAmountOfCash(DataUtil.BigDecimall
						.GetValueOrDefault(m.get("RefundedAmountOfCash")));
				o.setRefundedAmountOfGift(DataUtil.BigDecimall
						.GetValueOrDefault(m.get("RefundedAmountOfGift")));
				o.setSettlementAmountOfCoupon(DataUtil.BigDecimall
						.GetValueOrDefault(m.get("SettlementAmountOfCoupon")));
				o.setRefundProductNum(new BigDecimal(DataUtil.Integerr
						.GetValueOrDefault(m.get("RefundProductNum"))));
				o.setBrandId(DataUtil.Integerr.GetValueOrDefault(m
						.get("BrandId")));
				o.setPartialDiscount(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("PartialDiscount")));
				o.setPartialSellerCoupon(DataUtil.BigDecimall
						.GetValueOrDefault(m.get("PartialSellerCoupon")));
				o.setPartialSellerPromotion(DataUtil.BigDecimall
						.GetValueOrDefault(m.get("PartialSellerPromotion")));

				l.add(o);
			}
		}
		return l;
	}

	private static List<DbEntities.OrderInfo> convertToOrders(
			Sp_GetOrdersByOrderIds_v2 sp) {
		List<DbEntities.OrderInfo> l = new ArrayList<DbEntities.OrderInfo>();
		if (!DataUtil.isNullOrEmpty(sp.getOrderList())) {
			for (Map m : sp.getOrderList()) {

				DbEntities.OrderInfo o = new DbEntities.OrderInfo();

				o.setBasic_ID(DataUtil.Integerr.GetValueOrDefault(m
						.get("Basic_ID")));

				o.setBasic_CreatedTime(DataUtil.Stringg.getValueOrNull(m
						.get("Basic_CreatedTime")));
				o.setBasic_CancelledTime(DataUtil.Stringg.getValueOrNull(m
						.get("Basic_CancelledTime")));
				o.setBasic_AcceptedTime(DataUtil.Stringg.getValueOrNull(m
						.get("Basic_AcceptedTime")));
				o.setBasic_Source(DataUtil.Stringg.getValueOrNull(m
						.get("Basic_Source")));
				o.setBasic_Type(DataUtil.bool2Int(DataUtil.Booleann
						.GetValueOrDefault(m.get("Basic_Type"))));
				o.setBasic_Status(DataUtil.Integerr.GetValueOrDefault(m
						.get("Basic_Status")));
				o.setBasic_RiskStatus(DataUtil.Integerr.GetValueOrDefault(m
						.get("Basic_RiskStatus")));
				o.setBasic_TotalPrice(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("Basic_TotalPrice")));
				o.setBasic_Discount(DataUtil.BigDecimall.GetValueOrDefault(m
						.get("Basic_Discount")));
				o.setBuyer_ID(DataUtil.Stringg.getValueOrNull(m.get("Buyer_ID")));
				o.setBuyer_LoginId(DataUtil.Stringg.getValueOrNull(m
						.get("Buyer_LoginId")));
				o.setBuyer_Email(DataUtil.Stringg.getValueOrNull(m
						.get("Buyer_Email")));
				o.setBuyer_NickName(DataUtil.Stringg.getValueOrNull(m
						.get("Buyer_NickName")));
				o.setBuyer_Message(DataUtil.Stringg.getValueOrNull(m
						.get("Buyer_Message")));
				o.setSeller_ID(DataUtil.Stringg.getValueOrNull(m
						.get("Seller_ID")));
				o.setSeller_LoginId(DataUtil.Stringg.getValueOrNull(m
						.get("Seller_LoginId")));
				o.setSeller_Email(DataUtil.Stringg.getValueOrNull(m
						.get("Seller_Email")));
				o.setSeller_Comment(DataUtil.Stringg.getValueOrNull(m
						.get("Seller_Comment")));
				o.setConsignee_Name(DataUtil.Stringg.getValueOrNull(m
						.get("Consignee_Name")));
				o.setConsignee_Address(DataUtil.Stringg.getValueOrNull(m
						.get("Consignee_Address")));
				o.setConsignee_Postcode(DataUtil.Stringg.getValueOrNull(m
						.get("Consignee_Postcode")));
				o.setConsignee_Phone(DataUtil.Stringg.getValueOrNull(m
						.get("Consignee_Phone")));
				o.setConsignee_Tel(DataUtil.Stringg.getValueOrNull(m
						.get("Consignee_Tel")));
				o.setPayment_ActualPaid(DataUtil.BigDecimall
						.GetValueOrDefault(m.get("Payment_ActualPaid")));
				o.setPayment_1_PaidTime(DataUtil.Stringg.getValueOrNull(m
						.get("Payment_1_PaidTime")));
				o.setPayment_1_InternalTradingNo(DataUtil.Stringg
						.getValueOrNull(m.get("Payment_1_InternalTradingNo")));
				o.setPayment_1_ExternalTradingNo(DataUtil.Stringg
						.getValueOrNull(m.get("Payment_1_ExternalTradingNo")));
				o.setPayment_2_PaidTime(DataUtil.Stringg.getValueOrNull(m
						.get("Payment_2_PaidTime")));
				o.setTransfer_DeliveredTime(DataUtil.Stringg.getValueOrNull(m
						.get("Transfer_DeliveredTime")));
				o.setTransfer_ReceiptConfirmedTime(DataUtil.Stringg
						.getValueOrNull(m.get("Transfer_ReceiptConfirmedTime")));
				l.add(o);
			}
		}
		return l;
	}

	private static OrderTransferInfo GetTransferInfo(DbEntities.OrderInfo o1) {
		OrderTransferInfo o = new OrderTransferInfo();
		o.setDeliveredTime(o1.getTransfer_DeliveredTime());
		o.setReceiptConfirmedTime(o1.getTransfer_ReceiptConfirmedTime());
		return o;
	}

	private static List<OrderProductInfo> GetProductInfos(
			List<DbEntities.ProductInfo> products) {
		List<OrderProductInfo> l = new ArrayList<OrderProductInfo>();
		if (DataUtil.isNullOrEmpty(products) == false) {
			for (DbEntities.ProductInfo p : products) {
				OrderProductInfo o = new OrderProductInfo();
				o.setName(p.getName());
				o.setCatalogId(p.getCatalogId());
				o.setCatalogType(p.getCatalogType());
				o.setPackageNo(p.getPackageNo());
				o.setProductId(p.getProductId());
				o.setBondedArea(p.getBondedArea());
				o.setCount(p.getCount());
				o.setLogistics(p.getLogistics());
				o.setActivityId(p.getActivityId());
				o.setPrice(p.getPrice());
				o.setPropertyInfo(p.getPropertyInfo());
				o.setSKU(p.getSKU());
				o.setTotalPrice(p.getTotalPrice());
				o.setOriginalPrice(p.getOriginalPrice());
				o.setPartialFreight(p.getPartialFreight());
				o.setPartialYmtCoupon(p.getPartialYmtCoupon());
				o.setBrandId(p.getBrandId());
				List<Integer> categories = new ArrayList<Integer>();
				categories.add(p.getCategory1());
				categories.add(p.getCategory2());
				categories.add(p.getCategory3());
				o.setCategories(categories);
				OrderProductRefundInfo refundInfo = null;
				if (p.getRefundStatus() != null) {
					refundInfo = new OrderProductRefundInfo();
					refundInfo.setRefundAmount(p.getRefundAmount());
					refundInfo.setRefundedAmountOfCash(p
							.getRefundedAmountOfCash());
					refundInfo.setRefundedAmountOfGift(p
							.getRefundedAmountOfGift());
					refundInfo.setRefundProductNum(p.getRefundProductNum());
					refundInfo.setRefundStatus(p.getRefundStatus());
					refundInfo.setSalesRefundStatus(p.getSalesRefundStatus());
					refundInfo.setSettlementAmountOfCoupon(p
							.getSettlementAmountOfCoupon());
				}
				o.setRefundInfo(refundInfo);
				o.setPartialDiscount(p.getPartialDiscount());
				o.setPartialSellerCoupon(p.getPartialSellerCoupon());
				o.setPartialSellerPromotion(p.getPartialSellerPromotion());
				l.add(o);
			}
		}
		return l;
	}

	private static OrderPaymentInfo GetPaymentInfo(DbEntities.OrderInfo o1,
			DbEntities.OrderFundSummary summary) {
		OrderPaymentInfo o = new OrderPaymentInfo();
		o.setActualPaid(o1.getPayment_ActualPaid());
		List<OrderPaymentDetail> details = new ArrayList<OrderPaymentDetail>();
		if (o1.getPayment_1_PaidTime() != null
				&& !"".equals(o1.getPayment_1_PaidTime())) {
			OrderPaymentDetail d = new OrderPaymentDetail();
			d.setType(1);
			d.setPaidTime(o1.getPayment_1_PaidTime());
			d.setInternalTradingNo(o1.getPayment_1_InternalTradingNo());
			d.setExternalTradingNo(o1.getPayment_1_ExternalTradingNo());
			details.add(d);
		}
		if (o1.getPayment_2_PaidTime() != null
				&& !"".equals(o1.getPayment_2_PaidTime())) {
			OrderPaymentDetail d = new OrderPaymentDetail();
			d.setType(2);
			d.setPaidTime(o1.getPayment_2_PaidTime());
			details.add(d);
		}
		if (DataUtil.isNullOrEmpty(details) == false) {
			o.setDetails(details);
		}
		o.setSummary(summary);
		return o;
	}

	private static OrderBasicInfo GetBasicInfo(DbEntities.OrderInfo o1) {
		OrderBasicInfo o = new OrderBasicInfo();
		o.setID(o1.getBasic_ID());
		o.setType(o1.getBasic_Type());
		o.setStatus(o1.getBasic_Status());
		o.setSource(o1.getBasic_Source());
		o.setTotalPrice(o1.getBasic_TotalPrice());
		o.setDiscount(o1.getBasic_Discount());
		o.setCreatedTime(o1.getBasic_CreatedTime());
		o.setAcceptedTime(o1.getBasic_AcceptedTime());
		o.setCancelledTime(o1.getBasic_CancelledTime());
		return o;
	}

	private static OrderConsumerInfo GetBuerInfo(DbEntities.OrderInfo o1) {

		OrderConsumerInfo o = new OrderConsumerInfo();

		o.setID(o1.getBuyer_ID());
		o.setLoginId(o1.getBuyer_LoginId());
		o.setEmail(o1.getBuyer_Email());
		o.setNickName(o1.getBuyer_NickName());
		o.setMessage(o1.getBuyer_Message());
		return o;
	}
	private static OrderSellerInfo GetSellerInfo(DbEntities.OrderInfo o1) {
		OrderSellerInfo o = new OrderSellerInfo();
		o.setID(o1.getSeller_ID());
		o.setLoginId(o1.getSeller_LoginId());
		o.setEmail(o1.getSeller_Email());
		o.setComment(o1.getSeller_Comment());
		return o;
	}

	private static OrderConsigneeInfo GetConsigneeInfo(DbEntities.OrderInfo o1) {
		OrderConsigneeInfo o = new OrderConsigneeInfo();
		o.setName(o1.getConsignee_Name());
		o.setAddress(o1.getConsignee_Address());
		o.setPhone(o1.getConsignee_Phone());
		o.setPostcode(o1.getConsignee_Postcode());
		o.setTel(o1.getConsignee_Tel());
		return o;
	}

	private static SellerOrderInfo Init(SellerOrderInfo order) {
		if (order.getBasic().getType() > 0
				&& !DataUtil.isNullOrEmpty(order.getProducts())) {
			OrderProductInfo p = order.getProducts().get(0);
			p.setPrice(order.getBasic().getTotalPrice()
					.divide(new BigDecimal(p.getCount())));
			p.setTotalPrice(order.getBasic().getTotalPrice());
		}
		return order;
	}
}
